<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>收货地址列表</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/adress.css"/>
</head>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/iscroll.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/common.js"></script>
<body>
<div id="box">
    <div class="address_div">
        <span><img src="/img/00011.png" alt="" /></span>
        <p class="address_p"><a class="address_a" href="/UserCenter">个人中心</a></p>
    </div>
    <div class="wrap">

        @if($user->user_tel)
        <div class="main">
            <!--添加开始-->
            <div class="address">
                <div class="address_t">
                    <div class="address_infor">
                        <div class="name">{{ $user->username }}</div>
                        <div class="tel">{{ $user->user_tel }}</div>
                    </div>
                    <p class="ad">
                        <span class="sp">{{ $user->user_area }}</span>
                        <span class="sp">{{ $user->area_detail }}</span>
                    </p>
                </div>
                <div class="address_b">
                    <div class="address_b-l">
                        <div class="quan" id="chose_area" title="{{ $user->id }}">
                            @if($count == 0)
                                <img src="/img/00012.png" alt="" />
                            @else
                                <img src="/img/00014.png" alt="" />
                            @endif
                        </div>
                        默认地址
                    </div>

                </div>
            </div>
            @endif
            @foreach ($data as $info)
            <div class="address" id="areas_{{ $info->id }}">
                <div class="address_t">
                    <div class="address_infor">
                        <div class="name">{{ $info->user_name }}</div>
                        <div class="tel">{{ $info->user_tel }}</div>
                    </div>
                    <p class="ad">
                        <span class="sp">{{ $info->user_area }}</span>

                        <span class="sp">{{ $info->user_areadetails }}</span>
                    </p>
                </div>
                <div class="address_b">
                    <div class="address_b-l">
                        <div class="quan" id="chose_area" title="{{ $info->id }}">
                            @if($info->status)
                                <img src="/img/00012.png" alt="" />
                            @else
                                <img src="/img/00014.png" alt="" />
                            @endif
                        </div>
                        默认地址
                    </div>
                    <div class="address_b-r" title="{{ $info->id }}">
                        <div class="del quan">
                            <img src="/img/00010.png" alt="" />
                        </div>
                        删除
                    </div>

                </div>
            </div>
            @endforeach
            <!--添加结束-->
            <div class="address_over">
                <div class="addnew" onclick="window.location.href='/user-area/create?type={{ $_GET['type'] }}'">添加新地址</div>
            </div>
        </div>
    </div>
    <!--隐藏的删除弹框 start-->
    <div class="deleteDiv" style="display:none;">
        <div class="deleteDiv_tip">确认删除该收货地址吗？</div>
        <div class="deleteDiv_info">
			            <span id="" class="deleteDiv_info_left">
			                <input id="btnCancel" type="button" value="取 消" class="btn-green radius" />
			            </span>
            <span id="" class="deleteDiv_info_right">
			                <input id="btnDelTrue" type="button" value="确 认" class="btn-green radius hide" />
			            </span>
        </div>
    </div>
    <!--隐藏的删除弹框 end-->
    <div class="expurgate" style="display: none;">删除成功</div>
    <div class="mask" style="display:none;"></div>
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
</div>
</body>
<!--<script src="js/adress.js"></script>-->
<script>
    scroll();
    /*页面删除*/
    $(".address_b .address_b-r").click(function(){
        $('.deleteDiv').show();
        $('.mask').show();
        var id = $(this).attr('title');
        $('.deleteDiv_info_right').attr('title',id);
//        $(this).parent().parent().remove();
    });
    $('.deleteDiv_info_left').click(function () {
        $('.mask').hide();
        $('.deleteDiv').hide();
    });
    $('.deleteDiv_info_right').click(function () {
        var id = $(this).attr('title');
        $.ajax({
            url:'/user-area/'+id,
            type:'DELETE',
            data:{id:id},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            dataType:'json',
            success:function(data){
                if(data.success == true)
                {
                    $('.deleteDiv').hide();
                    $('.mask').hide();
                    $("#areas_"+id).remove();
                    $('.expurgate').show();
                    setTimeout(function(){
                        $('.expurgate').hide();
                    },600);
                }
            }
        })
    });

    /*数据库删除*/
    /*待做*/
</script>
</html>
<script>
    // 地址  功能  (设为默认地址)
    $('#chose_area img').click(function () {
        var id = $(this).parent('#chose_area').attr('title');
        var hide = $(this);
        $('#chose_area img').attr('src','/img/00014.png');
        hide.attr('src','/img/00012.png')
        $.ajax({
            url:'/set_userarea_status',
            type:'POST',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            data:{id:id},
            dataType:'json',
            success:function(data){
                if(data.success == true)
                {
                    var type  = '{{ $_GET['type'] }}';
                    if(type != 0)
                        window.location.href = '/userOrder?order_id='+type;
                }
            }
        })

    });
</script>